# -*- coding: utf8 -*-
import cx_Oracle

def findWAPURLByBarCode(req,barcode):
    formatString = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)" +"(HOST=%s)(PORT=%d)))(CONNECT_DATA=(SID=%s)))"
    args = ("10.0.0.95", 1521, "kaible")
    result = cx_Oracle.makedsn(*args)
    wapurl = 'start'

    try:
        try:
            ora = cx_Oracle.connect("kaible","kaible2006",result)
        
            curs = ora.cursor()
            curs.execute("select wapurl from wapproduct where barcode='%s'"%(barcode))

            row = curs.fetchone()
        finally:
            curs.close()
            ora.close()
    except Error:
        wapurl = 'error'
    else:
        if row:
            if(row[0]==None):
                wapurl = 'none'
            else:   
                wapurl = row[0]
        else:
            wapurl = 'no'

    return wapurl

##print findWAPURLByBarCode(None,'088089796000831')